package com.example.servicearea.dahua;


import com.example.servicearea.lib.NetSDKLib;

public  class ProcessThread extends Thread{
    PersonCapture device =null;
    public static boolean hasini=false;
    public static Object lock=new Object();
    public ProcessThread(PersonCapture device){
        this.device = device;
    }

    @Override
    public void run(){

        synchronized(lock) {
            if (!hasini)
                SDKUtil.init();
            hasini=true;
        }

        NetSDKLib.LLong handle = SDKUtil.login(device.getDeviceIp(), 37777, device.getUser(), device.getPwd());
        VideoStatSumCallback humanNumberStatisticCB=null;
        VehiclePass vehicleNumber = null;
        if(handle.longValue()==0){
            System.out.println("登陆失败");

        }else{
            device.setLoginHandle(handle);
            System.out.println("登陆成功");
            System.out.println(device.getDeviceType());
            if(device.getDeviceType().equals("车流摄像机")){
                vehicleNumber = new VehiclePass();
                NetSDKLib.LLong bHandle = SDKUtil.attachVehicleSummary(0,handle,vehicleNumber);
                if (bHandle.longValue()==0) {
                    System.out.println("车流訂閲失败");
                }else{
                device.setStatHandle(bHandle);
                vehicleNumber.setDeviceInfoMap(device);
                    System.out.println("车流訂閲成功");
                }
            }else
            {
                humanNumberStatisticCB = new VideoStatSumCallback();
                NetSDKLib.LLong aHandle = SDKUtil.attachPersonSummary(0,handle,humanNumberStatisticCB);
                if (aHandle.longValue()==0) {
                    System.out.println("客流訂閲失败");
                }else{
                    device.setStatHandle(aHandle);
                    humanNumberStatisticCB.setDeviceInfoMap(device);
                    System.out.println("客流訂閲成功");
                }
            }
        }

        while (true) {

            try {
                sleep(1000);
//                System.out.println(deviceInfo.getDeviceIp()+"||"+humanNumberStatisticCB.hashCode());

            } catch (InterruptedException e) {
                e.printStackTrace();
                break;
            }
        }

    }
}